import logging

import pytest

from resource.pom.settings import Settings
from utils.manager import Direction


class Test:
    app = Settings

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('步骤1.进入桌面，点击设置-辅助功能，单声道音频-开关测试，点击打开开关')
        device.start_ability(self.app.bundle_name, self.app.ability_name)
        device.dirc_fling(Direction.Down)
        device.click(*self.app.accessibility_features_item)
        device.refresh_layout()
        sound_switch = device.get_element_by_type('Toggle', index=2)
        sound_switch_status0 = sound_switch.get('checked')
        device.click_element(sound_switch)
        logging.info('预期结果1.开关正常开启')
        device.refresh_layout()
        sound_switch = device.get_element_by_type('Toggle', index=2)
        sound_switch_status1 = sound_switch.get('checked')
        assert sound_switch_status0 != sound_switch_status1, '单声道音频-开关未正常开启'

        logging.info('步骤2.点击关闭开关')
        device.click_element(sound_switch)
        logging.info('预期结果2.开关正常关闭')
        device.refresh_layout()
        sound_switch = device.get_element_by_type('Toggle', index=2)
        sound_switch_status2 = sound_switch.get('checked')
        assert sound_switch_status2 != sound_switch_status1, '单声道音频-开关未正常关闭'
